package exam;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * Tests the answer to the first stack question.
 * The text of the question is as follows:
 * "It is the night before Christmas and you want to make sure that you get to open your 
 *  presents ahead of everyone else tomorrow.  Rearrange the Stack<Present> so that your gifts 
 *  are on the top."
 * 
 * @author Branden Ogata
 *
 */

public class TestStackA00 extends Tester
{
  public static void main(String[] args)
  {
    final double POINTS = getPoints(args);
    final String TARGET_NAME = "Paul E. Gone";
    
    StackA00 question = new StackA00();
    Deque<Present> gifts = new LinkedList<Present>();
    Deque<Present> solution = new LinkedList<Present>();
    List<Present> presents = new LinkedList<Present>();
    presents.add(new Present("Sandy Beech", TARGET_NAME));    
    presents.add(new Present("Toby R. Notabee", TARGET_NAME));
    presents.add(new Present("Marcus Absent", TARGET_NAME));
    presents.add(new Present(TARGET_NAME, "Sandy Beech"));
    presents.add(new Present(TARGET_NAME, "Toby R. Notabee"));    
    
    // Empty
    question.movePresents(gifts, TARGET_NAME);
    System.out.println(test(Category.EQUALS, "movePresents([], \"" + TARGET_NAME + "\")", 
                            solution, gifts, 
                            percentageToPoints(EIGHTH, POINTS)));
    
    // One present belonging to subject
    gifts.push(presents.get(0));
    solution.push(presents.get(0));
    question.movePresents(gifts, TARGET_NAME);
    System.out.println(test(Category.EQUALS, "movePresents([match], " +
    		                                     "\"" + TARGET_NAME + "\")", 
                            solution, gifts, 
                            percentageToPoints(EIGHTH, POINTS)));
    
    // One present not belonging to subject
    gifts.clear();
    solution.clear();
    gifts.push(presents.get(4));
    solution.push(presents.get(4));
    question.movePresents(gifts, TARGET_NAME);
    System.out.println(test(Category.EQUALS, "movePresents([notMatch], \"" + TARGET_NAME + "\")", 
                            solution, gifts, 
                            percentageToPoints(EIGHTH, POINTS)));    
    
    // Two elements, subject present at top
    gifts.clear();
    solution.clear();
    gifts.push(presents.get(3));
    gifts.push(presents.get(0));
    solution.push(presents.get(3));
    solution.push(presents.get(0));
    question.movePresents(gifts, TARGET_NAME);
    System.out.println(test(Category.EQUALS, "movePresents([match, notMatch], " +
    		                                     "\"" + TARGET_NAME + "\")", 
                            solution, gifts, 
                            percentageToPoints(EIGHTH, POINTS)));    
    
    // Two elements, subject present not at top
    gifts.clear();
    solution.clear();
    gifts.push(presents.get(0));
    gifts.push(presents.get(3));
    solution.push(presents.get(3));
    solution.push(presents.get(0));
    question.movePresents(gifts, TARGET_NAME);
    System.out.println(test(Category.EQUALS, "movePresents([notMatch, match], " + 
                                             "\"" + TARGET_NAME + "\")", 
                            solution, gifts, 
                            percentageToPoints(EIGHTH, POINTS)));    

    
    // Three elements, subject present in middle
    gifts.clear();
    solution.clear();
    gifts.push(presents.get(4));
    gifts.push(presents.get(0));
    gifts.push(presents.get(3));
    solution.push(presents.get(4));
    solution.push(presents.get(3));
    solution.push(presents.get(0));
    question.movePresents(gifts, TARGET_NAME);
    System.out.println(test(Category.EQUALS, "movePresents([notMatch, match, notMatch], " + 
                                             "\"" + TARGET_NAME + "\")", 
                            solution, gifts, 
                            percentageToPoints(EIGHTH, POINTS)));    
    
    // Five elements, subject presents at 0, 2, 4
    gifts.clear();
    solution.clear();
    gifts.push(presents.get(1));
    gifts.push(presents.get(4));
    gifts.push(presents.get(2));
    gifts.push(presents.get(3));
    gifts.push(presents.get(0));
    solution.push(presents.get(4));
    solution.push(presents.get(3));
    solution.push(presents.get(1));
    solution.push(presents.get(2));
    solution.push(presents.get(0));
    question.movePresents(gifts, TARGET_NAME);
    System.out.println(test(Category.EQUALS, "movePresents([match, notMatch, match, " + 
                                             "notMatch, match], \"" + TARGET_NAME + "\")", 
                            solution, gifts, 
                            percentageToPoints(EIGHTH, POINTS)));    
    
    // Five elements, subject presents at 1, 3
    gifts.clear();
    solution.clear();
    gifts.push(presents.get(4));
    gifts.push(presents.get(2));
    gifts.push(presents.get(3));
    gifts.push(presents.get(0));
    gifts.push(presents.get(4));
    solution.push(presents.get(4));
    solution.push(presents.get(3));
    solution.push(presents.get(4));
    solution.push(presents.get(2));
    solution.push(presents.get(0));
    question.movePresents(gifts, TARGET_NAME);
    System.out.println(test(Category.EQUALS, "movePresents([notMatch, match, notMatch, " + 
                                             "match, notMatch], \"" + TARGET_NAME + "\")", 
                            solution, gifts, 
                            percentageToPoints(EIGHTH, POINTS)));    

    System.out.format("[%.2f/%.2f]%n", getTotalPoints(), POINTS);
  }
}
